package com.chaos.eurekaproducer.design.proxy;


import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author liaopeng
 * @title: CglibProxy
 * @projectName eureka-producer
 * @description: cglib动态代理
 * @date 2021/7/20下午3:07
 */
public class CglibProxy implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("before");
        //o是被代理对象，invokeSuper方法调用父类方法，在这之前可以实现切面逻辑
        Object result = methodProxy.invokeSuper(o, objects);
        System.out.println("after");
        return result;
    }
}
